package com.weiyuanstudio.nextstep.dto.database;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.weiyuanstudio.nextstep.persistence.entity.dbm.DatabaseBaselineTableColumn;
import lombok.Data;

/**
 * ALL_TAB_COLUMN表导出的JSON对象
 */
@Data
@JsonIgnoreProperties(ignoreUnknown = true) // 允许无视未知属性
public class AllTabColumn {
    @JsonProperty("OWNER")
    private String owner;
    @JsonProperty("TABLE_NAME")
    private String tableName;
    @JsonProperty("COLUMN_NAME")
    private String columnName;
    @JsonProperty("DATA_TYPE")
    private String dataType;
    @JsonProperty("DATA_LENGTH")
    private Integer dataLength;

    @Override
    public String toString() {
        return "AllTabColumn{" +
                "owner='" + owner + '\'' +
                ", tableName='" + tableName + '\'' +
                ", columnName='" + columnName + '\'' +
                '}';
    }

    /**
     * 转成实体类准备存库
     * @return 转换后的
     */
    public DatabaseBaselineTableColumn convertToEntity() {
        DatabaseBaselineTableColumn entity = new DatabaseBaselineTableColumn();
        entity.setTableName(this.tableName);
        entity.setFieldName(this.columnName);
        entity.setDataType(this.dataType);

        return entity;
    }
}
